﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Voluntariar.WEB.Util
{
    [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]

    public class StringValue : Attribute
    {
        public StringValue()
        {

        }
        #region Atributos / Propriedades

        private string Valor;

        public string ValorEnumerador
        {
            get { return Valor; }
            set { Valor = value; }
        }

        #endregion

        #region Construtor

        public StringValue(string ValorEnumerador)
        {
            this.Valor = ValorEnumerador;
        }

        #endregion

        #region Conversões de Consulta para o Objeto

        public string ConverterString(object data)
        {
            return !string.IsNullOrEmpty(data.ToString()) ? data.ToString() : string.Empty;
        }

        public decimal ConverterDecimal(object data)
        {
            if (data.ToString() == "7,95E-07")
            {
                string t = string.Empty;
            }
            return !string.IsNullOrEmpty(data.ToString()) ? Convert.ToDecimal(data) : 0;
        }

        public int ConverterInt(object data)
        {
            return !string.IsNullOrEmpty(data.ToString()) ? Convert.ToInt32(data) : 0;
        }

        public double ConverterDouble(object data)
        {
            return !string.IsNullOrEmpty(data.ToString()) ? Convert.ToDouble(data) : 0;
        }

        public DateTime ConverterDateTime(object data)
        {
            return !string.IsNullOrEmpty(data.ToString()) ? Convert.ToDateTime(data) : new DateTime();
        }

        public DateTime? ConverterDateTimeNull(object data)
        {
            return !string.IsNullOrEmpty(data.ToString()) ? Convert.ToDateTime(data) : new DateTime?();
        }
        public bool ConverterBool(object data)
        {
            return !string.IsNullOrEmpty(data.ToString()) ? Convert.ToBoolean(data.ToString()) : false;
        }

        public bool toBool(object data)
        {
            return Convert.ToBoolean(data);
        }

        #endregion

        #region Parametros de Consulta

        public object Parametro(int i)
        {
            return i > 0 ? i : (object)DBNull.Value;
        }

        public object Parametro(decimal i)
        {
            return i > 0 ? i : (object)DBNull.Value;
        }

        public object Parametro(double i)
        {
            return i > 0 ? i : (object)DBNull.Value;
        }

        public object Parametro(string s)
        {
            return !string.IsNullOrEmpty(s) ? s : (object)DBNull.Value;
        }

        public object Parametro(DateTime? dt)
        {
            return dt != null ? (DateTime)dt : (object)DBNull.Value;
        }

        #endregion

    }
}
